#include<bits/stdc++.h>
using namespace std;
int b[100005];
int zs()
{
    b[100005]={};
    int n,i,m,f=0,j;
    cin>>n;
    for(i=1;i<=n;i++)
     {
         cin>>m;
         b[i]=m;
     }
     for(i=n;i>=2;i--)
        for(j=i-1;j>=1;j--)
     {
         if(b[i]==b[j])
         {f=f+b[i];
         break;
         }
     }
     return f;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int n;
    cin>>n;
   for(int i=1;i<=n;i++)
    cout<<zs()<<endl;
    return 0;
}
